package com.github.prontera.controller;

import io.swagger.annotations.ApiOperation;

import java.time.OffsetDateTime;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.github.prontera.ApiVersion;
import com.github.prontera.domain.Tags;
import com.github.prontera.model.response.ObjectDataResponse;
import com.github.prontera.service.TagsService;
import com.github.prontera.util.Page;

/**
 * 技能标签
 * @author Alex
 */
@RestController
@RequestMapping(value = ApiVersion.MANAGE_V1_PREFIX + "/tag", produces = { MediaType.APPLICATION_JSON_UTF8_VALUE }, consumes = { MediaType.APPLICATION_JSON_UTF8_VALUE })
public class TagsController {

	@Autowired
	private TagsService tagsService;

	@ApiOperation(value = "查询标签内容", notes = "查询字典内容")
	@RequestMapping(value = "findTagList", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<Tags>> findTagList(@RequestBody Tags tag) {
		Page<Tags>  page = tagsService.findTagList(tag);
		return new ObjectDataResponse<Page<Tags>>(page);
	}
	
	@ApiOperation(value = "查询个人中心-->爱好标签", notes = "查询字典内容")
	@RequestMapping(value = "findInterestTagList", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<Tags>> findInterestTagList(@RequestBody Tags tag) {
		tag.setGroupType("interest");
		Page<Tags>  page = tagsService.findTagList(tag);
		return new ObjectDataResponse<Page<Tags>>(page);
	}
	
	@ApiOperation(value = "查询个人中心-->达人标签", notes = "查询字典内容")
	@RequestMapping(value = "findTalentTagList", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<Tags>> findTalentTagList(@RequestBody Tags tag) {
		tag.setGroupType("talent_tag");
		Page<Tags>  page = tagsService.findTagList(tag);
		return new ObjectDataResponse<Page<Tags>>(page);
	}

	@ApiOperation(value = "查询个人中心-->职业标签", notes = "查询字典内容")
	@RequestMapping(value = "findWorkTagList", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<Tags>> findWorkTagList(@RequestBody Tags tag) {
		tag.setGroupType("work");
		Page<Tags>  page = tagsService.findTagList(tag);
		return new ObjectDataResponse<Page<Tags>>(page);
	}
	
	@ApiOperation(value = "查询一级父类", notes = "查询字典内容")
	@RequestMapping(value = "findParentList", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Page<Tags>> findParentList(@RequestBody Tags tag) {
		Page<Tags>  page = tagsService.findTagList(tag);
		return new ObjectDataResponse<Page<Tags>>(page);
	}

	@ApiOperation(value = "修改标签内容", notes = "修改标签内容")
	@RequestMapping(value = "updateTag", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> updateTag(@RequestBody Tags tag) {
		if(tag!=null){
			tag.setUpdateTime(OffsetDateTime.now());
		}
		Integer res = tagsService.update(tag);
		return new ObjectDataResponse<Integer>(res);
	}

	@ApiOperation(value = "添加标签内容", notes = "添加标签内容")
	@RequestMapping(value = "addTag", method = RequestMethod.POST)
	@ResponseBody
	public ObjectDataResponse<Integer> addTag(@RequestBody Tags tag) {
		if(tag!=null){
			tag.setClientId(Long.parseLong("0"));
			tag.setCreateTime(OffsetDateTime.now());
			tag.setUpdateTime(OffsetDateTime.now());
			tag.setStatus(0);
		}
		Integer res = tagsService.insert(tag);
		return new ObjectDataResponse<Integer>(res);
	}

}
